//
//  MusicAlbumVC.m
//  leyitui
//  音乐相册模板
//  Created by 王大江 on 17/9/29.
//  Copyright © 2017年 xinleyi. All rights reserved.
//

#import "MusicAlbumVC.h"
#import "MusicAlbumCell.h"
#import "MHImagePickerMutilSelector.h"
#import "UITextView+PlaceHolder.h"

static NSString* const kCellID = @"MusicAlbumCell"; // UICollectionViewCell xid

@interface MusicAlbumVC ()<UICollectionViewDelegate, UICollectionViewDataSource,MHImagePickerMutilSelectorDelegate>
@property (weak, nonatomic) IBOutlet UICollectionView *mainCV;
@property (weak, nonatomic) IBOutlet UICollectionViewFlowLayout *flowLayout;



@end

@implementation MusicAlbumVC

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self setLayoutDataByColumNum:2 space:8.0 height:280];
    
    [self.mainCV registerNib:[UINib nibWithNibName:kCellID bundle:nil] forCellWithReuseIdentifier:kCellID];
    
}

-(void)setLayoutDataByColumNum:(int)columnsNum space:(CGFloat)space height:(CGFloat)height {
    CGFloat sum_width = self.mainCV.frame.size.width;
    CGFloat itemWidth = (sum_width - 10 - (columnsNum-1)*space)
    / columnsNum;
    self.flowLayout.itemSize = CGSizeMake(itemWidth, height);
    
}

- (NSInteger)collectionView:(UICollectionView *)view numberOfItemsInSection:(NSInteger)section;
{
    return 3;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)cv cellForItemAtIndexPath:(NSIndexPath *)indexPath;
{
    
    MusicAlbumCell *cell = [cv dequeueReusableCellWithReuseIdentifier:kCellID forIndexPath:indexPath];
    
    return cell;
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
//    //跳转到选择相片界面
//    NSString *content = [NSString stringWithFormat:@"第%ld个cell被点击了",indexPath.row];
//    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"标题" message:content preferredStyle:UIAlertControllerStyleAlert];
//    UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
////    UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"好的" style:UIAlertActionStyleDefault handler:nil];
//    [alertController addAction:cancelAction];
////    [alertController addAction:okAction];
//    [self presentViewController:alertController animated:YES completion:nil];
    
    MHImagePickerMutilSelector* imagePickerMutilSelector=[MHImagePickerMutilSelector standardSelector];//自动释放
    imagePickerMutilSelector.delegate = self;//设置代理
    UIImagePickerController* picker=[[UIImagePickerController alloc] init];
    picker.delegate=imagePickerMutilSelector;//将UIImagePicker的代理指向到imagePickerMutilSelector
    [picker setAllowsEditing:NO];
    picker.sourceType=UIImagePickerControllerSourceTypePhotoLibrary;
    picker.modalTransitionStyle= UIModalTransitionStyleCoverVertical;
    picker.navigationController.delegate=imagePickerMutilSelector;//将UIImagePicker的导航代理指向到imagePickerMutilSelector
    
    imagePickerMutilSelector.imagePicker = picker;//使imagePickerMutilSelector得知其控制的UIImagePicker实例
    [self presentViewController:picker animated:YES completion:nil];
    
    
    
}

#pragma mark 多选控件代理
-(void)imagePickerMutilSelectorDidGetImages:(NSArray *)imageArray
{
//    importItems=[[NSMutableArrayalloc] initWithArray:imageArray copyItems:YES];
    
}



















@end
